package umacis.data.description;

import java.util.Enumeration;
import java.util.Vector;

import umacis.lwuitcomponent.property.Properties;
import umacis.lwuitcomponent.property.PropertyAssigner;

import com.sun.lwuit.Component;
import com.sun.lwuit.Container;

public class ContainerDescription extends ComponentDescription {
	protected Vector children = new Vector();
	protected Properties propertiesToImpose = new Properties();
	
	public ContainerDescription(String uniqueName) {
		super(uniqueName);
	}
	
	public Component getLwuitComponentInstance() {
		return new Container();
	}
	
	public Component createLwuitComponent(Properties imposedProperties) {
		Container container = new Container();
		PropertyAssigner.getInstance().applyProperties(container, properties.defaultingTo(imposedProperties));
		buildContainer(container, propertiesToImpose.defaultingTo(imposedProperties));
		container.putClientProperty("Description", this);
		return container;
		
	}

	public void buildContainer(Container container, Properties propertiesToImpose) {
		Enumeration e = children.elements();
		while (e.hasMoreElements()) {
			ComponentDescription childComponentDescription = (ComponentDescription)e.nextElement();
			Component childCmp = childComponentDescription.createLwuitComponent(propertiesToImpose);
			container.addComponent(childCmp);	
		}
	}

}
